#-------------------------------------------------------------------------------
# Name:        ata
# Purpose:
#
# Author:      SUPER_紫电  QQ,911344755
#
# Created:     07/09/2022
# Copyright:   (c) SUPER_紫电 2022 All rights reserved.
# Licence:     <Modified BSD License>
#-------------------------------------------------------------------------------

from ctypes import Structure, c_ubyte
from ctypes.wintypes import USHORT, ULONG

UCHAR = c_ubyte

READ_SECTORS = 0x20
READ_SECTORS_EXT = 0x24
WRITE_SECTORS = 0x30
WRITE_SECTORS_EXT = 0x34
WRITE_VERIFY = 0x3C
READ_VERIFY_SECTORS = 0x40
READ_VERIFY_SECTORS_EXT = 0x42
ZERO_EXT = 0x44
WRITE_UNCORRECTABLE_EXT = 0x45
READ_BUFFER = 0xE4
WRITE_BUFFER = 0xE8
SECURITY_SET_PASSWORD = 0xF1
SECURITY_UNLOCK = 0xF2
SECURITY_ERASE_PREPARE = 0xF3
SECURITY_ERASE_UNIT = 0xF4
SECURITY_FREEZE_LOCK = 0xF5
SECURITY_DISABLE_PASSWORD = 0xF6

class _IDENTIFY_DEVICE_DATA(Structure):
    _pack_ = 1
    _fields_ = [
        ('GeneralConfiguration', USHORT), # word 0
        ('NumCylinders', USHORT), # word 1, obsolete
        ('SpecificConfiguration', USHORT), # word 2
        ('NumHeads', USHORT), # word 3, obsolete
        ('Retired1', USHORT*2), # word 4-5
        ('NumSectorsPerTrack', USHORT), # word 6, obsolete
        ('VendorUnique1', USHORT*3), # word 7-9
        ('SerialNumber', UCHAR*20), # word 10-19
        ('Retired2', USHORT), # word 20
        ('BufferSize', USHORT), # word 21
        ('ObsoluteWord22', USHORT), # word 22
        ('FirmwareRevision', UCHAR*8), # word 23-26
        ('ModelNumber', UCHAR*40), # word 27-46
        ('MaximumBlockTransfer', UCHAR), # word 47. 01h-10h = Maximum number of sectors that shall be transferred per interrupt on READ/WRITE MULTIPLE commands
        ('VendorUnique2', UCHAR),
        ('TrustedComputing', USHORT), # word 48
        ('Capabilities', USHORT*2), # word 49-50
        ('ObsoleteWords51', USHORT*2), # word 51-52
        ('TranslationFieldsValid', USHORT), # word 53, bit 0 - Obsolete, bit 1 - words 70:64 valid, bit 2 - word 88 valid
        ('NumberOfCurrentCylinders', USHORT), # word 54, obsolete
        ('NumberOfCurrentHeads', USHORT), # word 55, obsolete
        ('CurrentSectorsPerTrack', USHORT), # word 56, obsolete
        ('CurrentSectorCapacity', ULONG), # word 57, word 58, obsolete
        ('CurrentMultiSectorSetting', USHORT), # word 59
        ('UserAddressableSectors', ULONG), # word 60-61, for 28-bit commands
        ('ObsoleteWord62', USHORT),
        ('MultiWordDMASupport', USHORT), # word 63
        ('AdvancedPIOModes', USHORT), # word 64. bit 0:1 - PIO mode supported
        ('MinimumMWXferCycleTime', USHORT), # word 65
        ('RecommendedMWXferCycleTime', USHORT), # word 66
        ('MinimumPIOCycleTime', USHORT), # word 67
        ('MinimumPIOCycleTimeIORDY', USHORT), # word 68
        ('AdditionalSupported', USHORT), # word 69
        ('ReservedWords70', USHORT*5), # word 70 - reserved. word 71:74 - Reserved for the IDENTIFY PACKET DEVICE command
        ('ReservedWord75', USHORT), # Word 75
        ('SerialAtaCapabilities', USHORT*2), # Word 76 77
        ('SerialAtaFeaturesSupported', USHORT), # Word 78
        ('SerialAtaFeaturesEnabled', USHORT), # Word 79
        ('MajorRevision', USHORT), # word 80. bit 5 - supports ATA5, bit 6 - supports ATA6, bit 7 - supports ATA7, bit 8 - supports ATA8-ACS, bit 9 - supports ACS-2
        ('MinorRevision', USHORT), # word 81. T13 minior version number
        ('CommandSetSupport', USHORT*3), # Word 82 83 84
        ('CommandSetActive', USHORT*3), # Word 85 86 87
        ('UltraDMA', USHORT), # word 88. bit 0 - UDMA mode 0 is supported ... bit 6 - UDMA mode 6 and below are supported bit 8 - UDMA mode 0 is selected ... bit 14 - UDMA mode 6 is selected
        ('NormalSecurityEraseUnit', USHORT), # word 89
        ('EnhancedSecurityEraseUnit', USHORT), # word 90
        ('CurrentAPMLevel', USHORT), # word 91
        ('MasterPasswordID', USHORT), # word 92. Master Password Identifier
        ('HardwareResetResult', USHORT), # word 93
        ('CurrentAcousticValue', USHORT), # word 94. obsolete
        ('StreamMinRequestSize', USHORT), # word 95
        ('StreamingTransferTimeDMA', USHORT), # word 96
        ('StreamingAccessLatencyDMAPIO', USHORT), # word 97
        ('StreamingPerfGranularity', ULONG), # word 98, 99
        ('Max48BitLBA', ULONG*2), # word 100-103
        ('StreamingTransferTime', USHORT), # word 104. Streaming Transfer Time - PIO
        ('DsmCap', USHORT), # word 105
        ('PhysicalLogicalSectorSize', USHORT), # word 106
        ('InterSeekDelay', USHORT), # word 107.     Inter-seek delay for ISO 7779 standard acoustic testing
        ('WorldWideName', USHORT*4), # words 108-111
        ('ReservedForWorldWideName128', USHORT*4), # words 112-115
        ('ReservedForTlcTechnicalReport', USHORT), # word 116
        ('WordsPerLogicalSector', USHORT*2), # words 117-118 Logical sector size (DWord)
        ('CommandSetSupportExt', USHORT), # word 119
        ('CommandSetActiveExt', USHORT), # word 120
        ('ReservedForExpandedSupportandActive', USHORT*6),
        ('ReservedWord127', USHORT), # word 127. obsolete
        ('SecurityStatus', USHORT), # word 128
        ('ReservedWord129', USHORT*31), # word 129...159. Vendor specific
        ('CfaPowerMode1', USHORT), # word 160
        ('ReservedForCfaWord161', USHORT*7), # Words 161-167
        ('NominalFormFactor', USHORT), # Word 168
        ('DataSetManagementFeature', USHORT), # Word 169
        ('AdditionalProductID', USHORT*4), # Words 170-173
        ('ReservedForCfaWord174', USHORT*2), # Words 174-175
        ('CurrentMediaSerialNumber', USHORT*30), # Words 176-205
        ('SCTCommandTransport', USHORT), # Word 206
        ('ReservedWord207', USHORT*2), # Words 207-208
        ('BlockAlignment', USHORT), # Word 209
        ('WriteReadVerifySectorCountMode3Only', USHORT*2), # Words 210-211
        ('WriteReadVerifySectorCountMode2Only', USHORT*2), # Words 212-213
        ('NVCacheCapabilities', USHORT), # Word 214. obsolete
        ('NVCacheSizeLSW', USHORT), # Word 215. obsolete
        ('NVCacheSizeMSW', USHORT), # Word 216. obsolete
        ('NominalMediaRotationRate', USHORT), # Word 217, value 0001h means non-rotating media
        ('ReservedWord218', USHORT), # Word 218
        ('NVCacheOptions', USHORT), # Word 219. obsolete
        ('WriteReadVerifySectorCountMode', USHORT), # Word 220. Write-Read-Verify feature set current mode
        ('ReservedWord221', USHORT), # Word 221
        ('TransportMajorVersion', USHORT), # Word 222 Transport major version number
        ('TransportMinorVersion', USHORT), # Word 223
        ('ReservedWord224', USHORT*6), # Word 224...229
        ('ExtendedNumberOfUserAddressableSectors', ULONG*2), # Words 230...233 Extended Number of User Addressable Sectors
        ('MinBlocksPerDownloadMicrocodeMode03', USHORT), # Word 234 Minimum number of 512-byte data blocks per Download Microcode mode 03h operation
        ('MaxBlocksPerDownloadMicrocodeMode03', USHORT), # Word 235 Maximum number of 512-byte data blocks per Download Microcode mode 03h operation
        ('ReservedWord236', USHORT*19), # Word 236...254
        ('CheckSum', USHORT) # Word 255
    ]
IDENTIFY_DEVICE_DATA = _IDENTIFY_DEVICE_DATA

